<template>
	<view>
		<view class="head">
			<view style="font-weight: bold; font-size: 40rpx;">我参与的活动</view>
		</view>

		<activity-list :activity_list_data="activity_list_data" :scrollH="scrollH" :status="status" style="margin-bottom: 90rpx;"/>
		<fac-tab-bar :pagePath="'/pages/factory/joinactivitylist'" :activity_id="activity_id" :factory_id="factory_id" />
		<!-- <fac-tab-bar :pagePath="'/pages/factory/joinactivitylist'" :activity_id="activity_id" ></fac-tab-bar> -->

		<view class="top" :style="{'display':(flag===true? 'block':'none')}">
			<uni-icons class="topc" type="arrowthinup" size="30" @click="top"></uni-icons>
		</view>


	</view>
</template>

<script>
	import activityList from '@/components/factory/factory_joinactlist.vue'
	import uniIcons from '../../components/common/uni-icons/uni-icons.vue'
	import facTabBar from '../../components/factory/fac_tabbar.vue'
	export default {
		components: {
			activityList,
			uniIcons,
			facTabBar,
		},
		data() {
			return {
				scrollH: '',
				factory_id: '',
				activity_id: '',
				activity_list_data: [],
				status: 'more',
				page: 1,
				flag: false,
			};
		},
		onLoad(e) {
			this.activity_id = e.activity_id
			this.factory_id = e.factory_id
			this.$comm.appLogin(user_info=>{
				this.activity_list()
				this.get_scrollH()
			})
			
		},
		onShow() {
			// this.activity_list()
		},
		onPullDownRefresh() {
			this.loaddata()
		},
		onReachBottom() {
			if (this.status == 'nomore') return
			this.page++
			this.activity_list()
		},
		methods: {
			//获取已参加的活动列表
			activity_list() {
				this.$comm.request({
					url: 'api/factory_activity_list',
					method: 'GET',
					data: {
						page:this.page
					},
					success: res => {
						// this.activity_list_data = res.data.result.list;
						console.log(res, 'api/factory_activity_list');
						var list = res.data.result.list;
						this.activity_list_data = this.activity_list_data.concat(list)
						if (list.length < 10) {
							this.status = 'nomore'
						}
					}
				});
			},

			loaddata() {
				this.page = 1
				this.status = 'more'
				this.activity_list_data = []
				this.activity_list()
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},

			//获取可视区域高度
			get_scrollH() {
				uni.getSystemInfo({
					success: (res) => {
						this.scrollH = res.windowHeight - uni.upx2px(203)
						// console.log(res.windowHeight, '可视区域高度',this.scrollH)
					}
				})
			},

			//回到顶部
			top() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			onPageScroll(e) { //根据距离顶部距离是否显示回到顶部按钮
				if (e.scrollTop > 600) { //当距离大于600时显示回到顶部按钮
					this.flag = true
				} else { //当距离小于600时显示回到顶部按钮
					this.flag = false
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	@import '@/common/main.css';
	@import  '@/common/zcm-main.css';
	
	page {
		font-size: 30rpx;
		background-color: #F5F5F5;
	}

	.head {
		display: flex;
		justify-content: center;
		align-items: center;
		padding-top: 30rpx;

		.head-text {
			color: #ffffff;
			line-height: 2.5;
			background-color: #475dfc;
			width: 300rpx;
			text-align: center;
			border-radius: 50rpx;
			margin: 0rpx 15rpx 15rpx 15rpx;
		}
	}

	.top {
		position: relative;
		display: none;
		/* 先将元素隐藏 */
	}

	.topc {
		position: fixed;
		right: 0;
		// background: #F0F0F0;
		bottom: 105rpx;
		right: 10rpx;
		background-color: #FFF;
		border: solid 2rpx #475dfc;
		border-radius: 100rpx;
		height: 80rpx;
		width: 80rpx;
		line-height: 80rpx;
	}
</style>
